package com.yxkj.syh.app.huarong.data_center.model;

import com.syh.app.basic.utils.net.ApiObserver;
import com.trello.rxlifecycle2.LifecycleTransformer;
import com.yxkj.syh.app.huarong.api.ReportApi;
import com.yxkj.syh.app.huarong.bean.PagesRequest;
import com.yxkj.syh.app.huarong.util.RetrofitHelper;

import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * 创建者：SYH
 * 时间：2020/5/22 13:57
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class ReportModel {
    private static ReportModel reportModel;

    private ReportModel() {
    }

    public static ReportModel getReportModel() {
        if (reportModel == null) reportModel = new ReportModel();
        return reportModel;
    }

    private ReportApi getReportApi() {
        return RetrofitHelper.createApi(ReportApi.class);
    }

    public void report(Map<String,Object> pMap, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getReportApi().report(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void homeData(PagesRequest request, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getReportApi().homeData(request).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void appointments( LifecycleTransformer transformer, ApiObserver apiObserver) {
        getReportApi().appointments().compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void returnCarInfo(long id, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getReportApi().returnCarInfo(id).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void appointment(Map<String,Object> pMap, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getReportApi().appointment(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void unappointment(long id, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getReportApi().unappointment(id).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

}
